home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Dynamo 4.2 for GSBug 1.5b10 / rt.a < prev    next >
Encoding:
Text File  |  1990-09-21  |  22.7 KB  |  1,664 lines  |  [TEXT/MPS ]

  1. *******************************************************
  2. *                        *
  3. * DYNAMO                        *
  4. *                        *
  5. * Apple II 8-bit runtime library routines.        *
  6. * Copyright (C) 1990 Apple Computer.        *
  7. * Version 4.1                    *
  8. *                        *
  9. * Written by Eric Soldan, Apple II DTS        *
  10. *                        *
  11. *******************************************************
  12.  
  13.         include    ':dynamo.includes:sys.equ'
  14.         import    intspace
  15.  
  16. ******************
  17.  
  18.         export    rtreset
  19. rtreset        proc
  20.         export    numtocopy, chrhibiton, chrhibitoff
  21.         export    sign, readendchr, hexpadchr, padhex
  22.         ldy    #255
  23.         sty    numtocopy
  24.         sty    chrhibitoff
  25.         iny
  26.         sty    chrhibiton
  27.         sty    sign
  28.         sty    readendchr
  29.         lda    #'0'
  30.         sta    hexpadchr
  31.         lsr    padhex
  32.         rts
  33. numtocopy    dc.b    255        ;Will be set back to 255 after
  34.                     ;every string copy or append.
  35. chrhibitoff    dc.b    $FF
  36. chrhibiton    dc.b    0
  37. sign        dc.b    0
  38. readendchr    dc.b    0
  39. hexpadchr    dc.b    '0'
  40. padhex        dc.b    0
  41.         endp
  42.  
  43. ***
  44.  
  45.         export    hibitchrs
  46. hibitchrs    proc
  47.         lda    #$80        ;We don't need to set chrhibitoff
  48.         sta    chrhibiton    ;because it will either be a $7F
  49.         rts            ;or $FF, and in either case
  50.         endp            ;chrhibiton will turn it on anyway.
  51.  
  52. ***
  53.  
  54.         export    lowbitchrs
  55. lowbitchrs    proc
  56.         asl    chrhibiton    ;Was a $00 or $80, so this makes it $00.
  57.         lda    #$7F
  58.         sta    chrhibitoff
  59.         rts
  60.         endp
  61.  
  62. ***
  63.  
  64.         export    regchrs
  65. regchrs        proc
  66.         asl    chrhibiton
  67.         lda    #$FF
  68.         sta    chrhibitoff
  69.         rts
  70.         endp
  71.  
  72. ***
  73.  
  74.         export    rtcout
  75. rtcout        proc
  76.         stx    @keepx
  77.         and    chrhibitoff
  78.         ora    chrhibiton
  79.         jsr    $FDED
  80.         ldx    @keepx
  81.         rts
  82. @keepx        dc.b    0
  83.         endp
  84.  
  85. ***
  86.  
  87.         export    write
  88. write        proc
  89.         pla
  90.         sta    @getchr+1
  91.         pla
  92.         sta    @getchr+2
  93.         txa
  94.         pha
  95. @loop        inc    @getchr+1
  96.         bne    @getchr
  97.         inc    @getchr+2
  98. @getchr        lda    $2000        ;Address modified.
  99.         beq    @exit
  100.         jsr    rtcout
  101.         jmp    @loop
  102. @exit        pla
  103.         tax
  104.         lda    @getchr+2
  105.         pha
  106.         lda    @getchr+1
  107.         pha
  108.         rts
  109.         endp
  110.  
  111. ***
  112.  
  113.         export    writecr
  114. writecr        proc
  115.         txa
  116.         pha
  117.         lda    #13
  118.         jsr    rtcout
  119.         pla
  120.         tax
  121.         rts
  122.         endp
  123.  
  124. ***
  125.  
  126.         export    repeatsp
  127. repeatsp        proc
  128.         export    repeat
  129.         lda    #' '
  130. repeat        sty    @count
  131. @a        jsr    rtcout
  132.         dec    @count
  133.         bne    @a
  134.         rts
  135. @count        dc.b    0
  136.         endp
  137.         
  138.  
  139. ***
  140.  
  141.         export    wrcstr
  142. wrcstr        proc
  143.         sta    @getchr+1
  144.         sty    @getchr+2
  145.         txa
  146.         pha
  147. @getchr        lda    $2000        ;Address modified.        
  148.         beq    @exit
  149.         jsr    rtcout
  150.         inc    @getchr+1
  151.         bne    @getchr
  152.         inc    @getchr+2
  153.         bne    @getchr        ;Always.
  154. @exit        pla
  155.         tax
  156.         rts
  157.         endp
  158.  
  159. ***
  160. ***
  161. ***
  162.  
  163.         export    signed
  164. signed        proc
  165.         sec
  166.         ror    sign
  167.         rts
  168.         endp
  169.  
  170. ***
  171.  
  172.         export    unsigned
  173. unsigned        proc
  174.         lsr    sign
  175.         rts
  176.         endp
  177.  
  178. ***
  179.  
  180.         export    chngsgn
  181. chngsgn        proc
  182.         lda    intspace,x
  183.         eor    #$FF
  184.         clc
  185.         adc    #1
  186.         sta    intspace,x
  187.         pha
  188.         lda    intspace+1,x
  189.         eor    #$FF
  190.         adc    #0
  191.         sta    intspace+1,x
  192.         tay
  193.         pla
  194.         rts
  195.         endp
  196.  
  197. ***
  198.  
  199.         export    decoutl
  200. decoutl        proc
  201.         import    decout
  202.         ldy    #0
  203.         jmp    decout        ;jmp, instead of beq so we can be a lib.
  204.         endp
  205.  
  206. ***
  207.  
  208.         export    vdecout
  209. vdecout        proc
  210.         export    decout
  211.         lda    intspace+1,x
  212.         tay
  213.         lda    intspace,x
  214.  
  215. decout        sta    @templ
  216.         sty    @temph
  217.         lda    #'0'
  218.         sta    @temp2
  219.         txa
  220.         pha
  221.         bit    sign
  222.         bpl    @pos
  223.         tya
  224.         bpl    @pos
  225.         lda    #'-'
  226.         jsr    rtcout
  227.         lda    @templ
  228.         eor    #$FF
  229.         clc
  230.         adc    #1
  231.         sta    @templ
  232.         lda    @temph
  233.         eor    #$FF
  234.         adc    #0
  235.         sta    @temph
  236. @pos        ldx    #4
  237. @a        lda    #'0'
  238.         sta    @temp
  239. @b        lda    @templ
  240.         sec
  241.         sbc    @decl,x
  242.         tay
  243.         lda    @temph
  244.         sbc    @dech,x
  245.         bcc    @c
  246.         sta    @temph
  247.         sty    @templ
  248.         inc    @temp
  249.         bcs    @b
  250. @c        lda    @temp
  251.         dex
  252.         bmi    @e        ;Last digit -- print no matter what.
  253.         cmp    @temp2
  254.         beq    @a        ;Don't print leading 0's.
  255.         lsr    @temp2        ;Inval leading 0 test.
  256.         jsr    rtcout
  257.         jmp    @a
  258. @e        jsr    rtcout
  259.         pla
  260.         tax
  261.         rts
  262. @decl        dc.b    1
  263.         dc.b    10
  264.         dc.b    100
  265.         dc.b    1000-768
  266.         dc.b    10000-9984
  267. @dech        dc.b    1>>8
  268.         dc.b    10>>8
  269.         dc.b    100>>8
  270.         dc.b    1000>>8
  271.         dc.b    10000>>8
  272. @templ        dc.b    0
  273. @temph        dc.b    0
  274. @temp        dc.b    0
  275. @temp2        dc.b    0
  276.         endp
  277.  
  278. ***
  279.  
  280.         export    hexpad
  281. hexpad        proc
  282.         sta    hexpadchr
  283.         lsr    padhex
  284.         rts
  285.         endp
  286.  
  287. ***
  288.  
  289.         export    hexnopad
  290. hexnopad        proc
  291.         sec
  292.         ror    padhex
  293.         rts
  294.         endp
  295.  
  296. ***
  297.  
  298.         export    hexoutl
  299. hexoutl        proc
  300.         import    hexout
  301.         ldy    #0
  302.         clc
  303.         jmp    hexout+1        ;jmp, instead of beq so we can be a lib.
  304.         endp
  305.  
  306. ***
  307.  
  308.         export    vhexout
  309. vhexout        proc
  310.         export    hexout
  311.         import    hexpadchr
  312.         lda    intspace+1,x
  313.         tay
  314.         lda    intspace,x
  315.  
  316. hexout        sec
  317.         sta    @templ
  318.         txa
  319.         pha
  320.         ldx    #3
  321.         bcs    @aa
  322.         ldx    #1
  323.         ldy    @templ
  324. @aa        sty    @temph
  325.         lda    padhex
  326.         sta    @padhex
  327.         lda    hexpadchr
  328.         sta    @hexpadchr
  329. @loop        lda    #0
  330.         ldy    #4
  331. @a        asl    @templ
  332.         rol    @temph
  333.         rol    a
  334.         dey
  335.         bne    @a
  336.         tay
  337.         bne    @b
  338.         lda    @padhex
  339.         bmi    @nopad
  340.         lda    @hexpadchr
  341.         jsr    rtcout
  342.         jmp    @nopad
  343. @b        jsr    @doone
  344.         lsr    @padhex
  345.         lda    #'0'
  346.         sta    @hexpadchr
  347. @nopad        dex
  348.         bne    @loop
  349.         lda    @temph
  350.         lsr    a
  351.         lsr    a
  352.         lsr    a
  353.         lsr    a
  354.         tay
  355.         pla
  356.         tax
  357. @doone        lda    @hexdigit,y
  358.         jmp    rtcout
  359. @hexdigit    dc.b    '0123456789ABCDEF'
  360. @padhex        dc.b    0
  361. @hexpadchr    dc.b    0
  362. @templ        dc.b    0
  363. @temph        dc.b    0
  364.         endp
  365.  
  366. ***
  367.  
  368.         export    ldyvar
  369. ldyvar        proc
  370.         lda    intspace,y
  371.         pha
  372.         lda    intspace+1,y
  373.         tay
  374.         pla
  375.         rts
  376.         endp
  377.  
  378. ***
  379.  
  380.         export    mulconl
  381. mulconl        proc
  382.         import    mulcon
  383.         ldy    #0
  384.         jmp    mulcon        ;jmp, instead of beq so we can be a lib.
  385.         endp
  386.  
  387. ***
  388.  
  389.         export    mulvar
  390. mulvar        proc
  391.         export    mulcon, mulvall, mulvalh
  392.         import    multiply, setcon
  393.         jsr    ldyvar
  394.  
  395. mulcon        pha
  396.         lda    intspace,x
  397.         sta    mulvall
  398.         lda    intspace+1,x
  399.         sta    mulvalh
  400.         pla
  401.         jsr    multiply
  402.         jmp    setcon
  403. mulvall        dc.b    0
  404. mulvalh        dc.b    0
  405.         endp
  406.  
  407.         export    multiply
  408. multiply        proc
  409.         sta    @templ
  410.         sty    @temph
  411.         lda    #0
  412.         tay
  413. @a        lsr    mulvalh
  414.         ror    mulvall
  415.         bcc    @b
  416.         clc
  417.         adc    @templ
  418.         pha
  419.         tya
  420.         adc    @temph
  421.         tay
  422.         pla
  423. @b        asl    @templ
  424.         rol    @temph
  425.         pha
  426.         lda    mulvalh
  427.         ora    mulvall
  428.         cmp    #1
  429.         pla
  430.         bcs    @a
  431.         rts            ;Must exit with carry clear.
  432. @templ        dc.b    0
  433. @temph        dc.b    0
  434.         endp
  435.  
  436.         export    divconl
  437. divconl        proc
  438.         import    divcon
  439.         ldy    #0
  440.         jmp    divcon        ;jmp, instead of beq so we can be a lib.
  441.         endp
  442.  
  443. ***
  444.  
  445.         export    divvar
  446. divvar        proc
  447.         export    divcon
  448.         import    ldyvar
  449.         jsr    ldyvar
  450.  
  451. divcon        sta    @templ
  452.         sty    @temph
  453.         lda    #16
  454.         sta    @temp
  455.         lda    #0
  456.         sta    @temp2
  457.         sta    @temp3
  458. @a        asl    intspace,x
  459.         rol    intspace+1,x
  460.         rol    @temp2
  461.         rol    @temp3
  462.         lda    @temp2
  463.         sec
  464.         sbc    @templ
  465.         sta    @temp4
  466.         lda    @temp3
  467.         sbc    @temph
  468.         bcc    @b
  469.         sta    @temp3
  470.         lda    @temp4
  471.         sta    @temp2
  472.         inc    intspace,x
  473. @b        dec    @temp
  474.         bne    @a
  475.         lda    @temp2
  476.         ldy    @temp3
  477.         rts
  478. @templ        dc.b    0
  479. @temph        dc.b    0
  480. @temp        dc.b    0
  481. @temp2        dc.b    0
  482. @temp3        dc.b    0
  483. @temp4        dc.b    0
  484.         endp
  485.  
  486. ***
  487.  
  488.         export    addvar
  489. addvar        proc
  490.         export    addcon
  491.         import    ldyvar
  492.         jsr    ldyvar
  493.  
  494. addcon        pha
  495.         clc
  496.         adc    intspace,x
  497.         sta    intspace,x
  498.         tya
  499.         adc    intspace+1,x
  500.         sta    intspace+1,x
  501.         pla
  502.         rts
  503.         endp
  504.  
  505. ***
  506.  
  507.         export    addconl
  508. addconl        proc
  509.         ldy    #0
  510.         jmp    addcon        ;jmp, instead of beq so we can be a lib.
  511.         endp
  512.  
  513. ***
  514.  
  515.         export    subvar
  516. subvar        proc
  517.         export    subcon
  518.         import    ldyvar
  519.         jsr    ldyvar
  520.  
  521. subcon        pha
  522.         sta    @temp
  523.         lda    intspace,x
  524.         sec
  525.         sbc    @temp
  526.         sta    intspace,x
  527.         sty    @temp
  528.         lda    intspace+1,x
  529.         sbc    @temp
  530.         sta    intspace+1,x
  531.         pla
  532.         rts
  533. @temp        dc.b    0
  534.         endp
  535.  
  536. ***
  537.  
  538.         export    subconl
  539. subconl        proc
  540.         ldy    #0
  541.         jmp    subcon        ;jmp, instead of beq so we can be a lib.
  542.         endp
  543.  
  544. ***
  545.  
  546.         export    setconl
  547. setconl        proc
  548.         export    setcon
  549.         ldy    #0
  550.  
  551. setcon        sta    intspace,x
  552.         pha
  553.         tya
  554.         sta    intspace+1,x
  555.         pla
  556.         rts
  557.         endp
  558.  
  559. ***
  560.  
  561.         export    setzero
  562. setzero        proc
  563.         lda    #0
  564.         sta    intspace+1,x
  565.         sta    intspace,x
  566.         rts
  567.         endp
  568.  
  569. ***
  570.  
  571.         export    seteq
  572. seteq        proc
  573.         lda    intspace+1,y
  574.         sta    intspace+1,x
  575.         lda    intspace,y
  576.         sta    intspace,x
  577.         rts
  578.         endp
  579.  
  580. ***
  581.  
  582.         export    setvars
  583. setvars        proc
  584.         pla
  585.         sta    @gv+1
  586.         pla
  587.         sta    @gv+2
  588.         txa
  589.         pha
  590. @loop        jsr    @getval
  591.         cmp    #255
  592.         beq    @exit
  593.         tax
  594.         jsr    @getval
  595.         sta    intspace,x
  596.         jsr    @getval
  597.         sta    intspace+1,x
  598.         bcc    @loop        ;Always.
  599. @exit        pla
  600.         tax
  601.         lda    @gv+2
  602.         pha
  603.         lda    @gv+1
  604.         pha
  605.         rts
  606. @getval        inc    @gv+1
  607.         bne    @gv
  608.         inc    @gv+2
  609. @gv        lda    $2000        ;Address modified.
  610.         rts
  611.  
  612.         endp
  613.  
  614. ***
  615.  
  616.         export    xgty
  617. xgty        proc
  618.         import    vifequal, vifsgneq, xlty0
  619.         lda    sign
  620.         bpl    @a
  621.         jsr    vifsgneq
  622.         jmp    @b
  623. @a        jsr    vifequal
  624. @b        bcs    @rts
  625.         jmp    xlty0        ;jmp, instead of bcc so we can be a lib.
  626. @rts        rts
  627.         endp
  628.  
  629. ***
  630.  
  631.         export    xlty
  632. xlty        proc
  633.         export    xlty0
  634.         import    vifequal, vifsgneq
  635.         lda    sign
  636.         bpl    @a
  637.         jsr    vifsgneq
  638.         jmp    @b
  639. @a        jsr    vifequal
  640. @b        bcc    xltyrts
  641. xlty0        lda    intspace,x
  642.         pha
  643.         lda    intspace,y
  644.         sta    intspace,x
  645.         pla
  646.         sta    intspace,y
  647.         lda    intspace+1,x
  648.         pha
  649.         lda    intspace+1,y
  650.         sta    intspace+1,x
  651.         pla
  652.         sta    intspace+1,y
  653. xltyrts        rts
  654.         endp
  655.  
  656. ***
  657.  
  658.         export    ifequal
  659. ifequal        proc
  660.         sta    @lo+1
  661.         sty    @hi+1
  662.         lda    intspace+1,x
  663. @hi        cmp    #0        ;Operand modified.
  664.         bne    @exit
  665.         lda    intspace,x
  666. @lo        cmp    #0        ;Operand modified.
  667. @exit        php
  668.         lda    @lo+1
  669.         plp
  670.         rts            ;eq=eq, cs>=, cc<
  671.         endp
  672.  
  673. ***
  674.  
  675.         export    vifequal
  676. vifequal        proc
  677.         sta    @acc+1
  678.         lda    intspace+1,x
  679.         cmp    intspace+1,y
  680.         bne    @exit
  681.         lda    intspace,x
  682.         cmp    intspace,y
  683. @exit        php
  684. @acc        lda    #0        ;Operand modified.
  685.         plp
  686.         rts
  687.         endp
  688.  
  689. ***
  690.  
  691.         export    ifsgneq
  692. ifsgneq        proc
  693.         sta    @acc+1        ;Preserve acc.
  694.         tya
  695.         cmp    #$80        ;Carry set if right side negative.
  696.         eor    intspace+1,x    ;See if signs are the same.
  697.         bmi    @exit        ;Signs are different -- done.
  698.         bcs    @a        ;Variables are negative.
  699.         lda    @acc+1
  700.         jmp    ifequal        ;Variables are positive.
  701. @a        jsr    ifequal
  702.         beq    @rts        ;xreg variable is equal.
  703.         ror    a
  704.         eor    #$80
  705.         sec            ;not equal status.
  706.         rol    a
  707. @exit        php
  708. @acc        lda    #0        ;Operand modified.
  709.         plp
  710. @rts        rts            ;eq=eq, cs>=, cc<
  711.         endp
  712.  
  713. ***
  714.  
  715.         export    vifsgneq
  716. vifsgneq        proc
  717.         sta    @acc+1
  718.         sty    @yreg+1
  719.         lda    intspace,y    ;Load up the variable value and go do it.
  720.         pha
  721.         lda    intspace+1,y
  722.         tay
  723.         pla
  724.         jsr    ifsgneq
  725.         php
  726. @acc        lda    #0        ;Operand modified.
  727. @yreg        ldy    #0        ;Operand modified.
  728.         plp
  729.         rts
  730.         endp
  731.  
  732. ***
  733.  
  734.         export    seedrandom
  735. seedrandom    proc
  736.         export    randomval
  737.         adc    $C02E        ;Video counter.
  738.         pha
  739.         tya
  740.         adc    $C02E
  741.         tay
  742.         bne    @a
  743.         iny
  744. @a        pla
  745.         bne    @b
  746.         adc    #1
  747. @b        sta    randomval
  748.         sty    randomval+1
  749.         rts
  750. randomval    dc.w    0
  751.         endp
  752.  
  753. ***
  754.  
  755.         export    calcrandom
  756. calcrandom    proc
  757.         stx    @keepx        ;Keep this so we can restore the xreg.
  758.  
  759.         tax            ;Use 1 less than limit, so that we can
  760.         bne    @a        ;compute the smallest mask possible.  This
  761.         dey            ;way, if we are passed $100, we won't
  762. @a        dex            ;compute a mask of $1FF.
  763.         stx    @rndlimit    ;The carry was set by cmp #0, so the 
  764.         sty    @rndlimit+1    ;sbc #1 is okay.
  765.  
  766. * Figure a mask that is larger than or equal to the rndlimit (minus 1).  This will be
  767. * used against the calculated randomval before it is compared to the rndlimit.  If the
  768. * randomval is still too large, then we will get another.
  769.         ldx    #0
  770.         lda    @rndlimit+1
  771.         beq    @c        ;No hi-byte, so work on low-byte.
  772.         txa
  773.         inx
  774. @c        sec
  775.         rol    a
  776.         cmp    @rndlimit,x
  777.         bcc    @c
  778.         sta    @maskl,x
  779.         txa
  780.         eor    #1
  781.         tax
  782.         sbc    #1        ;Carry set.
  783.         sta    @maskl,x
  784.  
  785. @recalc        ldy    #19
  786. @d        asl    randomval
  787.         rol    randomval+1
  788.         bcc    @e
  789.         lda    randomval
  790.         eor    #$87
  791.         sta    randomval
  792.         lda    randomval+1
  793.         eor    #$1D
  794.         sta    randomval+1
  795. @e        dey
  796.         bne    @d
  797.  
  798.         ldy    randomval+1
  799.         ldx    randomval
  800.         bne    @f
  801.         dey
  802. @f        dex
  803.         tya
  804.         and    @maskh
  805.         tay
  806.         txa
  807.         and    @maskl
  808.         cpy    @rndlimit+1
  809.         bcc    @g
  810.         bne    @recalc
  811.         cmp    @rndlimit
  812.         bcc    @g
  813.         bne    @recalc
  814. @g        ldx    @keepx
  815.         rts
  816. @rndlimit    dc.w    0
  817. @keepx        dc.b    0
  818. @maskl        dc.b    0
  819. @maskh        dc.b    0
  820.         endp
  821.  
  822. ***
  823. ***
  824. ***
  825.  
  826.         export    strval
  827. strval        proc
  828.         export    midstrval
  829.         import    strinfo, strsign, strvalcount, strvaldigit, strlen, currentstr, nextchr
  830.         ldy    #0
  831. midstrval    jsr    strinfo
  832.         sta    @getchr+1
  833.         stx    @getchr+2
  834.         lda    #0
  835.         sta    strsign
  836.         sta    strvalcount
  837.         sta    strvaldigit
  838.         sta    @temp
  839.         sta    @temp2
  840. @sign        cpy    strlen
  841.         bcs    @exit        ;Indexed out of string at start.
  842.         jsr    @getchr        ;Decimal or hex...
  843.         cmp    #'+'
  844.         beq    @a        ;Ignore +'s when figuring sign.
  845.         cmp    #'-'        ;Find out if there is an even or odd # of -'s.
  846.         bne    @pos
  847.         inc    strsign
  848. @a        iny
  849.         inc    strvalcount
  850.         bcs    @sign        ;Always.
  851. @pos        cmp    #'$'
  852.         beq    @hex
  853. @b        cmp    #'0'
  854.         bcc    @exit        ;Not an int char, so we are done.
  855.         cmp    #'9'+1
  856.         bcs    @exit        ;Not an int char, so we are done.
  857.         iny
  858.         inc    strvalcount
  859.         inc    strvaldigit
  860.         sbc    #47        ;cclear
  861.         pha
  862.         ldx    @temp2        ;Multiply by 10.
  863.         lda    @temp
  864.         asl    a
  865.         rol    @temp2
  866.         asl    a
  867.         rol    @temp2
  868.         adc    @temp
  869.         sta    @temp
  870.         txa
  871.         adc    @temp2
  872.         asl    @temp
  873.         rol    a
  874.         sta    @temp2
  875.         pla
  876.         adc    @temp
  877.         sta    @temp
  878.         bcc    @c
  879.         inc    @temp2
  880. @c        cpy    strlen        ;See if we have more characters to look at.
  881.         bcs    @exit        ;No more characters to look at.
  882.         jsr    @getchr        ;Get the next character.
  883.         bcc    @b        ;Always.
  884. @exit        sty    nextchr        ;Save next character location.
  885.         ldx    currentstr
  886.         lda    @temp        ;Return value in acc,yreg.
  887.         ldy    @temp2
  888.         ror    strsign        ;Should be negative.
  889.         bcc    @rts
  890.         eor    #$FF
  891.         adc    #0        ;cset
  892.         pha
  893.         tya
  894.         eor    #$FF
  895.         adc    #0
  896.         tay
  897.         pla
  898. @rts        rts
  899. @getchr        lda    $2000,y        ;Address modified.
  900.         rts
  901. @hex        iny
  902.         inc    strvalcount
  903.         cpy    strlen
  904.         bcs    @exit
  905.         jsr    @getchr
  906.         cmp    #'0'
  907.         bcc    @exit
  908.         cmp    #'9'+1
  909.         bcc    @hexdigit
  910.         and    #$5F
  911.         cmp    #'A'
  912.         bcc    @exit
  913.         cmp    #'Z'+1
  914.         bcs    @exit
  915.         sbc    #6        ;Carry clear.
  916. @hexdigit    inc    strvaldigit
  917.         asl    @temp
  918.         rol    @temp2
  919.         asl    @temp
  920.         rol    @temp2
  921.         asl    @temp
  922.         rol    @temp2
  923.         asl    @temp
  924.         rol    @temp2
  925.         and    #$0F
  926.         ora    @temp
  927.         sta    @temp
  928.         jmp    @hex
  929. @temp        dc.b    0
  930. @temp2        dc.b    0
  931.         endp
  932.  
  933. ***
  934.  
  935.  
  936.         export    strinfo
  937. strinfo        proc
  938.         export    currentstr, strlen, maxstrlen, numchrs
  939.         export    strsign, strvalcount, strvaldigit, nextchr
  940.         import    strlens, maxstrlens, strlocs, numtocopy
  941.         stx    currentstr
  942.         lda    strlens,x    ;String number in xreg.
  943.         sta    strlen
  944.         lda    maxstrlens,x
  945.         sta    maxstrlen
  946.         txa
  947.         asl    a
  948.         tax
  949.         bcs    @a
  950.         lda    strlocs,x
  951.         pha
  952.         lda    strlocs+1,x
  953.         tax
  954.         pla
  955.         rts
  956. @a        lda    strlocs+$100,x
  957.         pha
  958.         lda    strlocs+$101,x
  959.         tax
  960.         pla
  961.         rts
  962. currentstr    dc.b    0
  963. strlen        dc.b    0
  964. maxstrlen    dc.b    0
  965. numchrs        dc.b    0
  966. strsign        dc.b    0
  967. strvalcount    dc.b    0
  968. strvaldigit    dc.b    0
  969. nextchr        dc.b    0
  970.         endp
  971.  
  972. ***
  973.  
  974.         export    strptr
  975. strptr        proc
  976.         import    strlocs
  977.         stx    currentstr
  978.         pha
  979.         txa
  980.         asl    a
  981.         tax
  982.         pla
  983.         bcs    @a
  984.         sta    strlocs,x
  985.         tya
  986.         sta    strlocs+1,x
  987.         bcc    @exit
  988. @a        sta    strlocs+$100,x
  989.         tya
  990.         sta    strlocs+$101,x
  991. @exit        ldx    currentstr
  992.         rts
  993.         endp
  994.  
  995. ***
  996.  
  997.         export    nullstr
  998. nullstr        proc
  999.         import    strlens
  1000.         lda    #0
  1001.         sta    strlens,x
  1002.         rts
  1003.         endp
  1004.  
  1005. ***
  1006.  
  1007.         export    out2str
  1008. out2str        proc
  1009.         export    out2stroff
  1010.         import    strlens, maxstrlens
  1011.         stx    @hook+1
  1012.         lda    cswl        ;See what the old output hook is.
  1013.         ldy    cswh
  1014.         cmp    #<@hook
  1015.         bne    @a        ;It isn't the string-collection hook.
  1016.         cpy    #>@hook
  1017.         beq    @rts        ;It already is the string-collection hook.
  1018. @a        sta    out2stroff+1
  1019.         sty    o2soff+1
  1020.         lda    #<@hook
  1021.         ldy    #>@hook
  1022.         sta    cswl
  1023.         sty    cswh
  1024. @rts        rts
  1025. @hook        ldx    #0        ;Modified.  (The collection string.)
  1026.         pha            ;Keep character.
  1027.         jsr    strinfo        ;Get the string info and set up the hook.
  1028.         sta    @savechr+1
  1029.         stx    @savechr+2
  1030.         ldx    @hook+1        ;The collection string.
  1031.         lda    strlens,x
  1032.         cmp    maxstrlens,x
  1033.         tay
  1034.         pla            ;The character to append.
  1035.         bcs    @rts        ;String already max length.
  1036. @savechr        sta    $2000,y        ;Modified.
  1037.         inc    strlens,x
  1038.         rts
  1039. out2stroff    lda    #0        ;Modified.
  1040. o2soff        ldy    #0        ;Modified.
  1041.         beq    @rts        ;Make sure that out2str was called at least once.
  1042.         sta    cswl
  1043.         sty    cswh
  1044. @rts        rts
  1045.  
  1046.         endp
  1047.  
  1048. ***
  1049.  
  1050.         export    prstr
  1051. prstr        proc
  1052.         lda    #255        ;xreg=str -- write entire string.
  1053.         export    prleftstr, prmidstr
  1054.  
  1055. prleftstr    ldy    #0        ;xreg=str, acc=numChrs
  1056.  
  1057. prmidstr        cmp    #0
  1058.         beq    @exit
  1059.         sta    numchrs        ;xreg=str, acc=numChrs, yreg=starting chr.
  1060.         jsr    strinfo
  1061.         sta    @getchr+1
  1062.         stx    @getchr+2
  1063. @loop        cpy    strlen
  1064.         bcs    @exit
  1065.         tya
  1066.         pha
  1067. @getchr        lda    $2000,y        ;Address modified.
  1068.         jsr    rtcout
  1069.         pla
  1070.         tay
  1071.         iny
  1072.         dec    numchrs
  1073.         bne    @loop
  1074. @exit        ldx    currentstr
  1075.         rts
  1076.         endp
  1077.  
  1078. ***
  1079.  
  1080.         export    leftstrcpy
  1081. leftstrcpy    proc
  1082.         export    strcpy, midstrcpy
  1083.         import    numtocopy, copystr
  1084.         sta    numtocopy    ;Number to copy in acc.
  1085.  
  1086. strcpy        lda    #0        ;Copy entire string.
  1087.  
  1088. midstrcpy    clc            ;String offset in acc.
  1089.         jmp    copystr        ;jmp, instead of bcc so we can be a lib.
  1090.         endp
  1091.  
  1092. ***
  1093.  
  1094.         export    leftstrcat
  1095. leftstrcat    proc
  1096.         export    strcat, midstrcat, copystr
  1097.         import    strlens, strlocs
  1098.         sta    numtocopy    ;Number to append in acc.
  1099.  
  1100. strcat        lda    #0        ;Append entire string.
  1101.  
  1102. midstrcat    sec            ;String offset in acc.
  1103.  
  1104. copystr        pha            ;Keep source offset.
  1105.         php            ;Keep copy or append status.
  1106.         jsr    strinfo
  1107.         sta    @dst+1
  1108.         stx    @dst+2
  1109.         lda    strlens,y
  1110.         sta    @srcstrlen
  1111.         tya
  1112.         asl    a
  1113.         tay
  1114.         bcs    @a
  1115.         lda    strlocs,y
  1116.         sta    @src+1
  1117.         lda    strlocs+1,y
  1118.         sta    @src+2
  1119.         bcc    @b
  1120. @a        lda    strlocs+$100,y
  1121.         sta    @src+1
  1122.         lda    strlocs+$101,y
  1123.         sta    @src+2
  1124. @b        ldx    #0
  1125.         plp            ;Get copy or append status.
  1126.         bcc    @c        ;Copy status.
  1127.         ldx    strlen        ;Append status.
  1128. @c        pla
  1129.         tay            ;Source offset.
  1130. @loop        cpy    @srcstrlen
  1131.         bcs    @exit
  1132.         cpx    maxstrlen
  1133.         bcs    @exit
  1134. @src        lda    $2000,y        ;Address modified.
  1135. @dst        sta    $2000,x        ;Address modified.
  1136.         inx
  1137.         iny
  1138.         dec    numtocopy
  1139.         bne    @loop
  1140. @exit        lda    #255        ;Set it back for next midstr operation.
  1141.         sta    numtocopy    ;The next one may only have 3 parameters.
  1142.         txa            ;xreg has destination string length.
  1143.         ldx    currentstr
  1144.         sta    strlens,x
  1145.         rts
  1146. @srcstrlen    dc.b    0
  1147.         endp
  1148.  
  1149. ***
  1150.  
  1151.         export    litstr
  1152. litstr        proc
  1153.         import    strlens
  1154.         pla
  1155.         sta    @getchr+1
  1156.         pla
  1157.         sta    @getchr+2
  1158.         jsr    strinfo
  1159.         sta    @putchr+1
  1160.         stx    @putchr+2
  1161.         ldy    #0
  1162. @loop        inc    @getchr+1
  1163.         bne    @getchr
  1164.         inc    @getchr+2
  1165. @getchr        lda    $2000        ;Address modified.
  1166.         beq    @exit
  1167.         cpy    maxstrlen
  1168.         bcs    @loop
  1169. @putchr        sta    $2000,y
  1170.         iny
  1171.         bne    @loop
  1172. @exit        lda    @getchr+2
  1173.         pha
  1174.         lda    @getchr+1
  1175.         pha
  1176.         ldx    currentstr
  1177.         tya
  1178.         sta    strlens,x
  1179.         rts
  1180.         endp
  1181.  
  1182. ***
  1183.  
  1184.         export    strchr
  1185. strchr        proc
  1186.         tay
  1187.         jsr    strinfo
  1188.         sta    @getchr+1
  1189.         stx    @getchr+2
  1190. @getchr        lda    $2000,y
  1191.         ldx    currentstr
  1192.         rts
  1193.         endp
  1194.  
  1195. ***
  1196.  
  1197.         export    strloc
  1198. strloc        proc
  1199.         jsr    strinfo
  1200.         pha
  1201.         txa
  1202.         tay
  1203.         ldx    currentstr
  1204.         pla
  1205.         rts
  1206.         endp
  1207.  
  1208. ***
  1209. ***
  1210. ***
  1211.  
  1212.         export    restore
  1213. restore        proc
  1214.         import    getdatabyte
  1215.         sta    getdatabyte+1
  1216.         sty    getdatabyte+2
  1217.         rts
  1218.         endp
  1219.  
  1220. ***
  1221.  
  1222.         export    getdatabyte
  1223. getdatabyte    proc
  1224.         lda    $2000
  1225.         inc    getdatabyte+1
  1226.         bne    @rts
  1227.         inc    getdatabyte+2
  1228. @rts        rts
  1229.         endp
  1230.  
  1231. ***
  1232.  
  1233.         export    readint
  1234. readint        proc
  1235.         jsr    getdatabyte
  1236.         sta    intspace,x
  1237.         pha
  1238.         jsr    getdatabyte
  1239.         sta    intspace+1,x
  1240.         tay
  1241.         pla
  1242.         rts
  1243.         endp
  1244.  
  1245. ***
  1246.  
  1247.         export    readstr
  1248. readstr        proc
  1249.         import    strlens
  1250.         jsr    strinfo
  1251.         sta    @putchr+1
  1252.         stx    @putchr+2
  1253.         ldy    #0
  1254. @loop        jsr    getdatabyte
  1255.         cmp    readendchr
  1256.         beq    @exit
  1257.         cpy    maxstrlen
  1258.         bcs    @loop
  1259. @putchr        sta    $2000,y
  1260.         iny
  1261.         bne    @loop
  1262. @exit        ldx    currentstr
  1263.         tya
  1264.         sta    strlens,x
  1265.         rts
  1266.         endp
  1267.  
  1268. ***
  1269.  
  1270.         export    readend
  1271. readend        proc
  1272.         sta    readendchr
  1273.         rts
  1274.         endp
  1275.  
  1276. ***
  1277. ***
  1278. ***
  1279.  
  1280.         export    arraybase
  1281. arraybase    proc
  1282.         export    arrayloc1, arrayloc2, arrayloc3
  1283.         export    arrayloc0l, arrayloc0h
  1284.         export    arrayloc1l, arrayloc1h
  1285.         export    arrayloc2l, arrayloc2h
  1286.         export    arrayloc3l, arrayloc3h
  1287.         export    dim0sizel, dim0sizeh
  1288.         export    dim1sizel, dim1sizeh
  1289.         export    dim2sizel, dim2sizeh
  1290.         export    dim3sizel, dim3sizeh
  1291.  
  1292.         sta    arrayloc0l    ;Save base address.
  1293.         sty    arrayloc0h
  1294.         jsr    arrayloc1    ;Set other addresses to base, as well.
  1295.         pla            ;Use return address to access array dimensions.    
  1296.         sta    @gb+1
  1297.         pla
  1298.         sta    @gb+2
  1299.         txa
  1300.         pha
  1301.         ldx    #0
  1302. @loop        jsr    @getb        ;Get lo-byte.
  1303.         sta    dim0sizel,x    ;This is safe, since we have an overflow byte below.
  1304.         php            ;Save status of lo-byte.
  1305.         jsr    @getb        ;Get hi-byte.
  1306.         plp            ;Status of lo-byte.
  1307.         bne    @a        ;This isn't the NULL word indicating the end.
  1308.         tay            ;Get status of hi-byte.
  1309.         beq    @loop2        ;This is the NULL word indicating the end.
  1310. @a        sta    dim0sizeh,x    ;This is safe, since we have an overflow word below.
  1311.         inx
  1312.         inx
  1313.         bne    @loop        ;Always.
  1314.  
  1315. @loop2        lda    dim0sizel-2,x    ;Save the last size for the rest of the dimensions.
  1316.         sta    dim0sizel,x
  1317.         inx
  1318.         cpx    #8
  1319.         bcc    @loop2
  1320.  
  1321.         pla
  1322.         tax
  1323.         lda    @gb+2
  1324.         pha
  1325.         lda    @gb+1
  1326.         pha
  1327.         rts
  1328.  
  1329. @getb        inc    @gb+1
  1330.         bne    @gb
  1331.         inc    @gb+2
  1332. @gb        lda    $2000        ;Address modified.
  1333.         rts
  1334.  
  1335. arrayloc1    sta    arrayloc1l
  1336.         sty    arrayloc1h
  1337. arrayloc2    sta    arrayloc2l
  1338.         sty    arrayloc2h
  1339. arrayloc3    sta    arrayloc3l
  1340.         sty    arrayloc3h
  1341.         sta    aptr
  1342.         sty    aptr+1
  1343.         rts
  1344.  
  1345. arrayloc0l    dc.b    0
  1346. arrayloc0h    dc.b    0
  1347. arrayloc1l    dc.b    0
  1348. arrayloc1h    dc.b    0
  1349. arrayloc2l    dc.b    0
  1350. arrayloc2h    dc.b    0
  1351. arrayloc3l    dc.b    0
  1352. arrayloc3h    dc.b    0
  1353. dim0sizel    dc.b    0        ;dim0 is the element size.
  1354. dim0sizeh    dc.b    0
  1355. dim1sizel    dc.b    0
  1356. dim1sizeh    dc.b    0
  1357. dim2sizel    dc.b    0
  1358. dim2sizeh    dc.b    0
  1359. dim3sizel    dc.b    0
  1360. dim3sizeh    dc.b    0
  1361.         dc.b    0        ;Overflow -- simplifies loop save/test.
  1362.         endp
  1363.  
  1364. ***
  1365.  
  1366.         export    varyindx1
  1367. varyindx1    proc
  1368.         export    arrayindx1, arraylindx1
  1369.         lda    intspace,y
  1370.         pha
  1371.         lda    intspace+1,y
  1372.         tay
  1373.         pla
  1374.  
  1375. arrayindx1    sta    mulvall
  1376.         sty    mulvalh
  1377.         lda    dim1sizel
  1378.         ldy    dim1sizeh
  1379.         jsr    multiply
  1380.         clc
  1381.         adc    arrayloc0l
  1382.         pha
  1383.         tya
  1384.         adc    arrayloc0h
  1385.         tay
  1386.         pla
  1387.         jmp    arrayloc1
  1388. arraylindx1    ldy    #0        ;Low-byte-only index entry point.
  1389.         beq    arrayindx1
  1390.         endp
  1391.  
  1392. ***
  1393.  
  1394.         export    varyindx2
  1395. varyindx2    proc
  1396.         export    arrayindx2, arraylindx2
  1397.         lda    intspace,y
  1398.         pha
  1399.         lda    intspace+1,y
  1400.         tay
  1401.         pla
  1402.  
  1403. arrayindx2    sta    mulvall
  1404.         sty    mulvalh
  1405.         lda    dim2sizel
  1406.         ldy    dim2sizeh
  1407.         jsr    multiply
  1408.         clc
  1409.         adc    arrayloc1l
  1410.         pha
  1411.         tya
  1412.         adc    arrayloc1h
  1413.         tay
  1414.         pla
  1415.         jmp    arrayloc2
  1416. arraylindx2    ldy    #0        ;Low-byte-only index entry point.
  1417.         beq    arrayindx2
  1418.         endp
  1419.  
  1420. ***
  1421.  
  1422.         export    varyindx3
  1423. varyindx3    proc
  1424.         export    arrayindx3, arraylindx3
  1425.         lda    intspace,y
  1426.         pha
  1427.         lda    intspace+1,y
  1428.         tay
  1429.         pla
  1430.  
  1431. arrayindx3    sta    mulvall
  1432.         sty    mulvalh
  1433.         lda    dim3sizel
  1434.         ldy    dim3sizeh
  1435.         jsr    multiply
  1436.         clc
  1437.         adc    arrayloc2l
  1438.         pha
  1439.         tya
  1440.         adc    arrayloc2h
  1441.         tay
  1442.         pla
  1443.         jmp    arrayloc3
  1444. arraylindx3    ldy    #0        ;Low-byte-only index entry point.
  1445.         beq    arrayindx3
  1446.         endp
  1447.  
  1448. ***
  1449.  
  1450.         export    vgetele
  1451. vgetele        proc
  1452.         export    getelel, getele, getele0
  1453.         import    floatspace
  1454.         lda    intspace,y
  1455.         pha
  1456.         lda    intspace+1,y
  1457.         tay
  1458.         pla
  1459.         dc.b    $2C        ;Skip the ldy #0 below.
  1460.  
  1461. getelel        ldy    #0
  1462.  
  1463. getele        sta    mulvall
  1464.         sty    mulvalh
  1465.         lda    dim0sizel
  1466.         ldy    dim0sizeh
  1467.         jsr    multiply
  1468.         adc    arrayloc3l    ;multiply clears the carry.
  1469.         sta    aptr
  1470.         tya
  1471.         adc    arrayloc3h
  1472.         sta    aptr+1
  1473.  
  1474. getele0        lda    dim0sizel    ;See which:  byte,int,float.
  1475.         ldy    #1        ;Efficient to set yreg here for byte,int.
  1476.         cmp    #2
  1477.         beq    @int
  1478.         bcs    @float
  1479.  
  1480. @byte        lda    #0
  1481.         beq    @a
  1482.  
  1483. @int        lda    (aptr),y
  1484. @a        sta    intspace+1,x
  1485.         dey
  1486.         lda    (aptr),y
  1487.         sta    intspace,x
  1488.         rts
  1489.  
  1490. @float        txa
  1491.         pha
  1492.         dey
  1493. @b        lda    (aptr),y
  1494.         iny
  1495.         sta    floatspace,x
  1496.         inx
  1497.         cpy    #5
  1498.         bcc    @b
  1499.         pla
  1500.         tax
  1501.         rts
  1502.         endp
  1503.  
  1504. ***
  1505.  
  1506.         export    getnextele
  1507. getnextele    proc
  1508.         lda    aptr
  1509.         clc
  1510.         adc    dim0sizel
  1511.         sta    aptr
  1512.         bcc    @a
  1513.         inc    aptr+1
  1514. @a        jmp    getele0
  1515.         endp
  1516.  
  1517. ***
  1518.  
  1519.         export    vputele
  1520. vputele        proc
  1521.         export    putelel, putele, putele0
  1522.         import    floatspace
  1523.         lda    intspace,y
  1524.         pha
  1525.         lda    intspace+1,y
  1526.         tay
  1527.         pla
  1528.         dc.b    $2C        ;Skip the ldy #0 below.
  1529.  
  1530. putelel        ldy    #0
  1531.  
  1532. putele        sta    mulvall
  1533.         sty    mulvalh
  1534.         lda    dim0sizel
  1535.         ldy    dim0sizeh
  1536.         jsr    multiply
  1537.         adc    arrayloc3l    ;multiply clears the carry.
  1538.         sta    aptr
  1539.         tya
  1540.         adc    arrayloc3h
  1541.         sta    aptr+1
  1542.  
  1543. putele0        lda    dim0sizel    ;See which:  byte,int,float.
  1544.         ldy    #0        ;Efficient to set yreg here for byte,int.
  1545.         cmp    #2
  1546.         beq    @int
  1547.         bcs    @float
  1548.  
  1549. @int        lda    intspace,x
  1550.         sta    (aptr),y
  1551.         bcc    @rts        ;Element size is byte.
  1552.         lda    intspace+1,x
  1553.         iny
  1554.         sta    (aptr),y
  1555. @rts        rts
  1556.  
  1557. @float        txa
  1558.         pha
  1559. @a        lda    floatspace,x
  1560.         inx
  1561.         sta    (aptr),y
  1562.         iny
  1563.         cpy    #5
  1564.         bcc    @a
  1565.         pla
  1566.         tax
  1567.         rts
  1568.         endp
  1569.  
  1570. ***
  1571.  
  1572.         export    putnextele
  1573. putnextele    proc
  1574.         lda    aptr
  1575.         clc
  1576.         adc    dim0sizel
  1577.         sta    aptr
  1578.         bcc    @a
  1579.         inc    aptr+1
  1580. @a        jmp    putele0
  1581.         endp
  1582.         
  1583. ***
  1584.  
  1585.         export    deref
  1586. deref        PROC
  1587.         sta    @getbyte+1
  1588.         sty    @getbyte+2
  1589.         jsr    @getbyte        ;Get low-byte.
  1590.         tya
  1591.         inc    @getbyte+1
  1592.         bne    @getbyte
  1593.         inc    @getbyte+2
  1594. @getbyte        ldy    $2000        ;Address modified.        
  1595.         rts
  1596.  
  1597.         endp
  1598.  
  1599. ***
  1600.  
  1601.         export    aderefz
  1602. aderefz        PROC
  1603.         export    aderef
  1604.         lda    $2000        ;Address modified.
  1605.         inc    aderefz+1
  1606.         bne    @rts
  1607.         inc    aderefz+2
  1608. @rts        rts
  1609. aderef        sta    aderefz+1
  1610.         jsr    aderefz        ;Get low-byte.
  1611.         pha
  1612.         jsr    aderefz
  1613.         sta    aderefz+2
  1614.         pla
  1615.         rts
  1616.  
  1617.         endp
  1618.  
  1619. ***
  1620.  
  1621.         export    yderefz
  1622. yderefz        PROC
  1623.         export    yderef
  1624.         ldy    $2000        ;Address modified.
  1625.         inc    yderefz+1
  1626.         bne    @rts
  1627.         inc    yderefz+2
  1628. @rts        rts
  1629. yderef        sty    yderefz+1
  1630.         jsr    yderefz        ;Get low-byte.
  1631.         sty    @lo
  1632.         jsr    yderefz
  1633.         sty    yderefz+2
  1634.         ldy    @lo
  1635.         rts
  1636. @lo        dc.b    0
  1637.  
  1638.         endp
  1639.  
  1640. ***
  1641.  
  1642.         export    vderef        ;x-reg variable deref.
  1643. vderef        PROC
  1644.         pha
  1645.         lda    intspace,x
  1646.         sta    @getbyte+1
  1647.         lda    intspace+1,x
  1648.         sta    @getbyte+2
  1649.         jsr    @getbyte        ;Get low-byte.
  1650.         sta    intspace,x
  1651.         inc    @getbyte+1
  1652.         bne    @a
  1653.         inc    @getbyte+2
  1654. @a        jsr    @getbyte
  1655.         sta    intspace+1,x
  1656.         pla
  1657.         rts
  1658. @getbyte        lda    $2000        ;Address modified.        
  1659.         rts
  1660.  
  1661.         endp
  1662.  
  1663.         end
  1664.